using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using Common.Utilities;
using Common.Utilities.Dispatcher;

namespace Workflows.Components.ETL
{
    /// <summary></summary>
    [Serializable]
    public class SyncDbTableOutput:ResultBase
    {
        private int _TotalRecordsUpdated;
        /// <summary></summary>
        public int TotalRecordsUpdated
        {
            get { return _TotalRecordsUpdated; }
            set { _TotalRecordsUpdated = value; }
        }
        /// <summary></summary>
        public SyncDbTableOutput():base(Guid.Empty, Guid.Empty)
        {
            this._TotalRecordsUpdated = 0;
        }
        /// <summary></summary>
        public SyncDbTableOutput(Guid componentID, Guid jobTicketID, int totalRecUpdated)
            : base(componentID, jobTicketID)
        {
            this._TotalRecordsUpdated = totalRecUpdated;
        }
        /// <summary></summary>
        public override XmlNode Serialize(ref XmlDocument xDoc, ref XmlNode parentNode)
        {
            XmlNode xNode = XmlDataUtil.AddElement(ref xDoc, parentNode, "Output");
            XmlDataUtil.UpdateAttribute(ref xDoc, xNode, "Type", this.GetType().FullName);
            XmlDataUtil.UpdateAttribute(ref xDoc, xNode, "WorkerID", this.OwnerWorkerInstanceID.ToString());
            XmlDataUtil.UpdateAttribute(ref xDoc, xNode, "FinishTime", this.FinishTime.ToString());

            XmlDataUtil.UpdateAttribute(ref xDoc, xNode, "RecordUpdated", this.TotalRecordsUpdated.ToString());

            return xNode;
        }
        /// <summary></summary>
        public override ResultBase Instantiate(XmlNode xNode)
        {
            if (xNode.Attributes.GetNamedItem("Type").Value == this.GetType().FullName)
            {
                SyncDbTableOutput output = new SyncDbTableOutput();
                // output.OwnerComponentID = new Guid(xNode.Attributes.GetNamedItem("ComponentID").Value);
                output.OwnerWorkerInstanceID = new Guid(xNode.Attributes.GetNamedItem("WorkerID").Value);
                output.FinishTime = DateTime.Parse(xNode.Attributes.GetNamedItem("FinishTime").Value);

                output.TotalRecordsUpdated = int.Parse(xNode.Attributes.GetNamedItem("RecordUpdated").Value);
                return output;
            }
            else
            {
                throw new Exception("Unable to instantiate output: invalid type specified in xml node");
            }
        }
    }
}
